<?php

namespace app\adminapi\controller\v1\exam;

use app\adminapi\controller\AuthController;
use app\services\exam\ExamQuestService;
use think\facade\App;

class ExamQuestion extends AuthController
{
    public function __construct(App $app, ExamQuestService $service)
    {
        parent::__construct($app);
        $this->services = $service;
    }


    public function index(){
        $where = $this->request->getMore([
            ['website_id',$this  -> website],
            ['page',1],
            ['pageSize',20],
            ['title',''],
            ['type',''],
            ['paper_name',''],
            ['pattern',''],
        ]);
        return app() -> make('json') -> successful($this -> services -> index($where));
    }

    public function createOrUpdate(){
        $where = $this->request->getMore([
            ['id',''],
            ['title',''],
            ['show_type',''],
            ['type',''],
            ['pattern',''],
            ['score',''],
            ['paper_name',''],
            ['lenght',''],
            ['A',''],
            ['B',''],
            ['C',''],
            ['D',''],
            ['E',''],
            ['F',''],
            ['dan',''],
            ['duo',''],
            ['pan',''],
            ['tian',''],
            ['content',''],
            ['json',''],
            ['website_id',$this  -> website],
        ]);
        return app() -> make('json') -> successful($this -> services -> createOrUpdate($where));
    }

    public function delete(){
        $where = $this->request->getMore([
            ['id','']
        ]);
        return app() -> make('json') -> successful($this -> services -> delete($where));
    }

    public function downloadTemplate(){
      $file =  $_SERVER['DOCUMENT_ROOT'] . '/excelTemplate/' . '试题导入模板.xls';
      return download($file,'试题导入模板.xls');
    }
}